// 用户信息数据
function createUserList() {
    return [
        {
            userId: 1,
            avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
            username: 'admin',
            password: '111111',
            desc: '平台管理员',
            roles: ['平台管理员'],
            buttons: ['cuser.detail', 'cuser.user'],
            routes: ['home'],
            token: 'system.admin',
        },
        {
            userId: 2,
            avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
            username: 'system',
            password: '111111',
            desc: '系统管理员',
            roles: ['系统管理员'],
            buttons: ['cuser.detail', 'cuser.user'],
            routes: ['home'],
            token: 'xyasda.system',
        }
    ]
}


export default [
    // 用户登录
    {
        url: '/api/user/login',
        method: 'post',
        response: ( {body} ) => {
            const { username, password } = body;
            const checkUser = createUserList().find(v => v.username === username && v.password === password)
            if (checkUser) {
                return {
                    code: 200,
                    data: checkUser.token,
                    message: '登录成功'
                }
            } else {
                return {
                    code: 400,
                    message: '用户名或密码错误'
                }

            }
        }
    },
    // 获取用户信息
    {
        url: '/api/user/info',
        method: 'get',
        response: (request)  => {
            // 获取token
            const token =  request.headers.token;
         
            // 匹配用户信息
            const checkUser = createUserList().find(v => v.token === token)
            if (checkUser) {
                return {
                    code: 200,
                    data: checkUser,
                    message: '获取用户信息成功'
                }
            } else {
                return {
                    code: 400,
                    message: '获取用户信息失败'
                }
            }

        }

    }
]






